package leetcode.code1535;

import java.util.Arrays;

public class Solution {

	public int getWinner(int[] arr, int k) {
		if (k >= arr.length - 1) {
			return Arrays.stream(arr).max().getAsInt();
		}
		int ans = arr[0], cnt = 0;
		for (int i = 1; i < arr.length && cnt < k; i++) {
			if (ans > arr[i]) {
				cnt++;
			} else {
				ans = arr[i];
				cnt = 1;
			}
		}
		return ans;
	}
}
